<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 全局倒置与局部倒置 -->
    <script>
      var isIdealPermutation = function (nums) {
        for (let i = 0; i < nums.length; i++) {
          for (let j = i + 1; j < nums.length; j++) {
            let a = 0,
              b = 0
            if (nums[j] < nums[i]) {
              if (j == i + 1) {
                b = 1
              }
              a++
            }
            if (a !== b) return false
          }
        }
        return true
      }
      console.log(isIdealPermutation([1, 0, 2]))
    </script>
  </body>
</html>
